package br.edu.unifei.greedyiip;

import br.edu.unifei.mestrado.commons.graph.GraphWrapper;
import br.edu.unifei.mestrado.commons.partition.AbstractPartition;
import br.edu.unifei.mestrado.commons.partition.BestPartition;
import br.edu.unifei.mestrado.mn.TwoWayMultinivel;

public abstract class MultinivelGreedyIIP extends TwoWayMultinivel {

	private int k;
	
	private GreedyIIP iip;

	public MultinivelGreedyIIP(int k, int runs, GreedyIIP greedyIIP) {
		this.k = k;
		iip = greedyIIP;
	}

	@Override
	protected BestPartition executePartition(GraphWrapper graph) {
		AbstractPartition partition = iip.executeIIP(graph, true);
		BestPartition bestPartition = partition.createBestPartition();
		return bestPartition;
	}

	@Override
	protected BestPartition refineGraph(GraphWrapper graph, int level) {
		
		AbstractPartition partition = iip.executeIIP(graph, false);
		BestPartition bestPartition = partition.createBestPartition();
		return bestPartition;
	}

	@Override
	protected void preprocess(GraphWrapper initialGraph) {
		iip.updateSizeBounds(initialGraph, k);

		iip.initMapPartitionSize(k);
	}
}
